﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Global;

namespace Helper
{
    public static class MainFormHelper
    {
        public static void UpdateFilePathAndName(string path)
        {
            Settings.CURRENT_FILE_PATH = path;
            var names = Settings.CURRENT_FILE_PATH.Split('\\');
            Settings.CURRENT_FILE_NAME = names.Last();
        }

        public static void SaveFilePathAndNameToRegistry()
        {
            //save the same values to the registry
            var regMySoft = Utility.CreateRegistryKey();
            if (regMySoft != null)
            {
                using (var tempKey = regMySoft.OpenSubKey(Constant.REGISTRY.SETTINGS, true))
                {
                    if (tempKey != null)
                    {
                        tempKey.SetValue(Constant.REGISTRY.CURRENT_FILE_PATH, Settings.CURRENT_FILE_PATH);
                        tempKey.SetValue(Constant.REGISTRY.CURRENT_FILE_NAME, Settings.CURRENT_FILE_NAME);
                        tempKey.Close();
                    }
                }
            }
        }

        public static int GetRandom(int a, int b)
        {
            Random r = new Random();

            if (r.Next(0, a + b + 1) <= a)
                return Constant.CURRENT_ITEM.VOCABULARY;
            else 
                return Constant.CURRENT_ITEM.NOTE;
        }
    }
}
